package com.hx.observer.advice;

import java.util.Observable;
import java.util.Observer;

/**
 * @author Huathy
 * @date 2021-09-06 21:48
 * @description JDK提供的一种观察者实现方式
 * 被观察者
 */
public class Forum extends Observable {
    private String name = "{论坛-被观察者}";

    private static Forum notice = null;

    private Forum() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static Forum getInstance() {
        if (notice == null) {
            notice = new Forum();
        }
        return notice;
    }

    public void publish(Info info){
        System.out.println(info.getUname()+"-发布了一条消息，内容："+info.getMsg());
        setChanged();
        notifyObservers(info);
    }
}
